package com.zxl.yjb.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zxl.yjb.GlideApp;
import com.zxl.yjb.R;

import java.util.List;

public class NewsImageAdapter extends BaseQuickAdapter<String,BaseViewHolder> {


    public NewsImageAdapter(int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        ImageView view = (ImageView) helper.getView(R.id.iv_pic);
        WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        if (windowManager != null) {
            DisplayMetrics outMetrics = new DisplayMetrics();
            windowManager.getDefaultDisplay().getMetrics(outMetrics);
            Display display = windowManager.getDefaultDisplay();
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.height=display.getWidth()/3;
            layoutParams.width = display.getWidth()/3;
            view.setLayoutParams(layoutParams);
        }

        GlideApp.with(mContext).load(item).into(view);
    }
}
